<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="clearfix">
        <span>个人修读课程表</span>
      </div>
      <div v-if="loading" class="loading-container">
        <el-skeleton :rows="5" animated />
      </div>
      <div v-else>
        <el-table :data="courses" border style="width: 100%">
          <el-table-column prop="subId" label="课程编号" align="center" />
          <el-table-column prop="courseName" label="课程名称" align="center" />
          <el-table-column prop="score" label="成绩" align="center" />
          <el-table-column prop="subCode" label="学分" align="center" />
          <el-table-column prop="status" label="修读状态" align="center" />
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getStudentCourses } from '@/api/student'

export default {
  name: 'StudentCourses',
  data() {
    return {
      loading: true,
      courses: []
    }
  },
  mounted() {
    this.fetchCourses()
  },
  methods: {
    async fetchCourses() {
      this.loading = true
      try {
        const studentId = this.$store.state.user.token
        const response = await getStudentCourses(studentId)
        if (response.success) {
          this.courses = response.data
        } else {
          this.$message.error(response.message)
        }
      } catch (error) {
        this.$message.error('获取数据失败')
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.app-container {
  padding: 20px;
}

.loading-container {
  padding: 20px;
}
</style>
